<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="black" name="apple-mobile-web-app-status-bar-style" />
<meta content="telephone=no" name="format-detection" />
<meta content="email=no" name="format-detection" />
<title>传感数据</title>
<link rel="stylesheet" href="../../css/s_plus.css" />
<!--<link rel="stylesheet" href="../../css/mui.min.css" />-->
<link rel="stylesheet" href="../../css/hui.css" />

<link rel="stylesheet" href="../../css/base.css" />
<link rel="stylesheet" href="../../css/layout.css" />
<link rel="stylesheet" href="../../css/choice.css" />
<script type="text/javascript" src="../../libs/vue.js" ></script>
<script type="text/javascript" src="../../js/jquery.1.9.1.min.js" ></script>
<script type="text/javascript" src="../../js/app/url.js" ></script>
<script type="text/javascript" src="../../libs/hui.js" ></script>
<script type="text/javascript" src="../../js/s_plus.js" ></script>
<script type="text/javascript" src="../../js/md5.js"></script>
<script type="text/javascript" src="../../js/app/api.js"></script>
		<script type="text/javascript" src="../../js/mui.min.js"></script>
				<script type="text/javascript" src="../../js/app/ble.js"></script>
				



</head>
<body class="bg_gray">
	<div id="app">
	<header class="f_l maxbox subhead">
  <a class="back"  @click="back"><i class="iconfont">&#xe605;</i></a>
  <!--<input type="hidden" value="{{sensor.NUMBER}}" />-->
  <h1>传感数据 </h1>
</header>
  <section class="f_l maxbox sensor_data">
    <ul>
    	      
    	      
 
      <li>
        <b>NB卡信号值</b>
        <span>{{nb.xinhao}} </span>
      </li>
      <li>
        <b>NB卡号</b>
        <span>{{nb.card}}   </span>
      </li>
      <li>
        <b>电池电压值</b>
        <span>{{status.dy}} </span>
      </li>
      <li>
        <b>井盖是否破损</b>
        <span>{{status.jgwps}}</span>
      </li>
      


       
      <li>
        <b>底部是否开启</b>
        <span>{{status.db}}</span>
      </li>
      <li>
        <b>中部是否开启</b>
        <span>{{status.zb}}</span>
      </li>
      <li>
        <b>顶部是否开启</b>
        <span>{{status.dingbu}}</span>
      </li>
    
    <li>
						<b>压力值</b>
						<span>
							{{status.ylz}}
						</span>
					</li>
					<li>
						<b>水深</b>
						<span>
						{{status.ss}}
						</span>
					</li>
					<li>
						<b>燃气浓度值</b>
						<span>
							{{status.rqndz}}
						</span>
					</li>
      
      
      
    </ul>
    
    <!--<div><button>报装</button></div>-->
    
    
  </section>
  
  <section class="f_l maxbox mar_t mar_f t_c" v-if="type =='baozhuang'">
						<a class="btn mian_btn" @click="shezhi">设置</a>&nbsp;&nbsp;&nbsp;
		<a class="btn mian_btn" @click="baozhuang">报装</a>
<p>&nbsp;</p>
			</section>
  </div>
  <script>
  	var bleConnect;
  	
  	var sp;
  mui.plusReady(function() {
  		 	
  	 bleConnect = plus.blecontroler;
  	var returnStr = bleConnect.init()


  		
  		

  sp = new Vue({
	el: "#app",
	data: {
		Tid: "",
//		status:{ dy:"",jgwps:"",db:"",zb:"",dingb:""},
		status:{
			dy: "",
									jgwps: "",
									db: "",
									zb: "",
									dingbu: "",
									ylz: "",
									ss: "",
									rqndz: ""
		},
		nb: {xinhao: "",card: ""},
		sensor: {},
		type:""
	},
	mounted: function() {
		var tid=localStorage.getItem("pid");
		
		var type=localStorage.getItem("type");
		this.type=type;
		console.log("tid---"+tid);
		this.Tid=tid;
		
//		getNB();
		
		getNewSensor();
		
	},
	methods: {
		
		
		
		shezhi:function(){
					    localStorage.setItem("nosubmit","no");

						var zdCode=localStorage.getItem("pid");

						localStorage.setItem("Tid",zdCode);
					localStorage.setItem("zd_id",zdCode);

						

				hui.open("/modules/terminal/setting.html?time="+apiManage.getNow(), {}, true, {Tid:zdCode});

		},
		baozhuang:function(){
//			this.wakeUp();
			var zdCode=localStorage.getItem("pid")
			localStorage.setItem("Tid",zdCode);
//							hui.open("/modules/alerm/sensor_data.html?time"+apiManage.getNow(), {}, true, {});	
		          			hui.open("/modules/terminal/expand.html?s="+apiManage.getNow(), {}, true, {});
		},
		
			//唤醒终端
			wakeUp:function () {
				if(!this.Tid || this.Tid.length == 0) {
					hui.toast("请先获取终端编号");
					return;
				}

				var command = "5A1109" + sp.Tid + "01";
				console.log("唤醒命令" + command);
				bleConnect.writeData(command, function(ret) {
					console.log("返回数据:" + ret);
//					sp.notifyList = sp.notifyList.concat("唤醒成功: " + ret);
					console.log("唤醒成功");
				}, function(err) {
					hui.closeLoading();
					alert(err);
				});
			}
			,
		showBroke:function(param){
			if(param=='1'){
			   	return "破损";
			   }
			   else{
			   	return "未破损";

			   }
		},
		showStatus:function(param){
			   if(param=='1'){
			   	return "开启";
			   }
			   else{
			   	return "关闭";

			   }
		},
		back: function() {
			localStorage.setItem("pid","");
			localStorage.setItem("type","");
			hui.back();
		},
		chuangan: function() {
			var workId = this.zd.workId;
			localStorage.setItem("workId", workId);
			hui.open("work_show.html", {}, true, {});
		}
		
	}
		
});





  					
  					
  					
});

		//获取最新传感数据 2019-1-10  接口文档 2.2.3
			function getNewSensor() {
		var tid=localStorage.getItem("pid");

				var command = "5a1608" + tid;
				console.log("获取最新传感数据 " + command);
               hui.loading("");
				bleConnect.writeData(command, function(ret) {
					console.log("返回 最新传感数据:" + ret);
					hui.closeLoading();
					//					hui.toast(ret);

					setTimeout(function() {
						getNB();
					}, 200);

					var paramString = ret;

					var dianya = paramString.substr(6, 4);
					console.log('电压值---' + parseInt(dianya, 16) / 1000);
					dianya = parseInt(dianya, 16) / 1000;

					var wps = paramString.substr(10, 2);

					wps = parseInt(wps, 16);
					if(wps == 0) {
						wps = "未破损";
					} else {
						wps = "破损";

					}

					var dib = paramString.substr(12, 2);
					dib = parseInt(dib, 16);

					dib = (dib == 0) ? "关闭" : "开启";

					var zb = paramString.substr(14, 2);
					zb = parseInt(zb, 16);

					zb = (zb == 0) ? "关闭" : "开启";

					var dingb = paramString.substr(16, 2);
					dingb = parseInt(dingb, 16);
					dingb = (dingb == 0) ? "关闭" : "开启";

					var rqndz = paramString.substr(18, 4);
					rqndz = parseInt(rqndz, 16) / 100 + " %";

					var ylz = paramString.substr(22, 4);
					ylz = parseInt(ylz, 16) + " KPa";
					var ss = paramString.substr(26, 4);

					ss = parseInt(ss, 16) / 100 + "米";

					console.log("井盖未破损:" + wps + " 井盖底部开启：" + dib + "  井盖中部未开启: " + zb + " 井盖顶部未开启: " + dingb + " 燃气浓度值:" + rqndz + " 压力值: " + ylz + " , 水深:" + ss);

					sp.status.dy = dianya;
					sp.status.jgwps = wps;
					sp.status.db = dib;
					sp.status.zb = zb;
					sp.status.dingbu = dingb;

					sp.status.ylz = ylz;
					sp.status.ss = ss;
					sp.status.rqndz = rqndz;

					//					sp.notifyList = sp.notifyList.concat("获取固件版本号成功: " + ret);

				}, function(err) {
					hui.closeLoading();
					console.log(err);
					//					alert(err);
				});
			}



	//获取井盖终端状态
			function getStatus () {
		var tid=localStorage.getItem("pid");

				var command = "5a1608" + tid;
				console.log("获取井盖终端状态 " + command);
				bleConnect.writeData(command, function(ret) {
					if(ret.indexOf("state") != -1) {
						return;
					}

					console.log("返回数据:" + ret);
//					sp.notifyList = sp.notifyList.concat("获取井盖终端状态成功: " + ret);

					console.log("获取井盖终端状态成功: " + ret);


					var status = ret.substr(2, 2);
					if(status == '22') {
						//							hui.toast("获取成功 ");
					} else {
						//						hui.toast("获取失败");

					}
					console.log("dianya:---" + ret.substr(22, 4));
					var dianya1 = ret.substr(22, 4);
					//					var dianya2 = ret.substr(26,2);

					//					井盖无破损，底部开启，中部未开启，顶部未开启
					var wps = ret.substr(26, 2);
					var db = ret.substr(28, 2);
					var zb = ret.substr(30, 2);
					var dingb = ret.substr(32, 2);
					var abc = Math.round(parseFloat(parseInt(dianya1, 16))) / 1000;

					wps = (wps == "00") ? "无破损" : "有破损";
					db = (db == "00") ? "未开启" : "开启";
					zb = (zb == "00") ? "未开启" : "开启";
					dingb = (dingb == "00") ? "未开启" : "开启";

					var paramString = "电压: " + abc + ",井盖井盖无破损:" + wps + ",底部:" + db + ",中部:" + zb + ",顶部:" + dingb;
					console.log(paramString);
               
// { dy:"",jgwps:"",db:"",zb:"",db:""}
				sp.status.dy=abc;
				sp.status.jgwps=wps;
				sp.status.db=db;
				sp.status.zb=zb;
				sp.status.dingb=dingb;
//					sp.status = paramString;
console.log(JSON.stringify(sp.status));
				}, function(err) {
					hui.closeLoading();
					console.log(err);
					//					alert(err);
				});
			}
		
		//获取NB信息
			function getNB()  {
//				$("#nbBtn").hide();
		var tid=localStorage.getItem("pid");

				var command = "5a1508" + tid;
				console.log("获取NB信息 " + command);

					hui.loading("");
				bleConnect.writeData(command, function(ret) {
					console.log("返回数据:" + ret);
					hui.closeLoading();
//					sp.notifyList = sp.notifyList.concat("获取NB信息成功: " + ret);

					console.log(ret);
					var all = ret;
					var xinhao = all.substr(14, 2);
					var number2 = all.substr(16, 20);

					//					parseInt(sixteen,16);
					console.log("信号: " + parseInt(xinhao, 16) + ",  卡号:" + number2);
					//					hui.toast("信号: "+parseInt(xinhao,16)+",  卡号:"+number2);
					sp.nb.xinhao = parseInt(xinhao, 16);
					sp.nb.card = number2;
					console.log("sp.nb---" + JSON.stringify(sp.nb));

//					setTimeout(function() {
//						getNewSensor();
//					}, 200);
					
				

				}, function(err) {
					hui.closeLoading();
					console.log(err);
					//					alert(err);
				});
			}
 
  </script>
</body>
</html>